.netCHARTING v6.0 Documentation Send comments on this topic.
Mapping Data and Layers
Getting Started > General Tutorials > Mapping > Mapping Data and Layers

Glossary Item Box

MapDataEngine object

The MapDataEngine class exposes methods that populate MapLayer objects with data and map information retrieved from shape or ecw files. The following code snippet demonstrates simple usage of this engine loading the states.shp shapefile into a map layer:

[C#]

MapLayer myLayer = MapDataEngine.LoadLayer("states.shp");
[Visual Basic]

MapLayer myLayer = MapDataEngine.LoadLayer("states.shp")

The myLayer object now contains visual and statistical data about each US state. These states are represented as Shape objects. Each shape has a number of attributes that contain the statistical data. This data is stored as key value pairs and the keys for the shape attributes are stored under the string array myLayer.AttributeNames.

Sample Mapping/IteratingShapes.aspx styles a number of shapes based on the value of the country code attribute.

Importing database data

One of the above mentioned attribute keys is 'State_Abbr' which represents the state abbreviation. Consider we also have a database containing additional information about these states that we want to use on the map. A column named 'state' in this database contains the same state abbreviations. This will allow matching the map shapes with this data. The first step is to get a DataTable containing the state column along with any other data columns to bind with the map. Next, the mapLayer will be bound with this table.

[C#]

myLayer.ImportData(myDataTable,"State_Abbr","state");
[Visual Basic]

myLayer.ImportData(myDataTable,"State_Abbr","state")

The parameters are the DataTable, the shape attribute and the matching DataTable column name to match. All other columns in the DataTable will be added to the map layer and shapes as additional attributes.

Sample Mapping/ImportShapefileData.aspx imports additional information about states from an access database to be used with the map layer.


Add layers to a map

Adding a layer to the map can be done easily with the following code:

[C#]

Chart.Mapping.MapLayerCollection.Add(myLayer);
[Visual Basic]

Chart.Mapping.MapLayerCollection.Add(myLayer)

 

Add Points Manually

Shape layers use a single type of shape such as polygons or points. Therefore, a new map layer must be created with points to add to a map. A point can be added based on a Lat/Long GPS coordinate or reversed in the form of Long/Lat as shown below:

 

[C#]
MapLayer ml = new MapLayer();
ml.AddPoint(50,100);
Chart.Mapping.MapLayerCollection.Add(ml);
[Visual Basic]
Dim ml AS new MapLayer()
ml.AddPoint(50,100)
Chart.Mapping.MapLayerCollection.Add(ml)
Sample: AddMapPoint.aspx


Add Lines manually

Again, a new map layer is required to add lines to a map. Lines can be added using Lat/Long GPS coordinates or reversed in the form of Long/Lat. A line object can be specified in the AddLine parameters to specify the styling when drawn. Line caps are also supported.

Sample: MapAddLine.aspx
©2010. All Rights Reserved.